<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

/**
 * App\Models\OrderItem
 *
 * @property int $id
 * @property int $order_id belongs to this order
 * @property int|null $vendor_id belongs to this vendor
 * @property int $product_id belongs to this product
 * @property int $product_sku_id belongs to this sku
 * @property string|null $product_title
 * @property string|null $sku_name
 * @property string|null $sku_attr_value_index
 * @property array|null $sku_attr_value
 * @property int $amount how many usr bought
 * @property string $cost the cost price
 * @property string $total_cost
 * @property string $price final price
 * @property string $total_amount
 * @property string $delivery_status
 * @property string|null $delivery_data data about delivery
 * @property string|null $refund_number
 * @property string $refund_status
 * @property string|null $refund_failed_reason
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \App\Models\Order $order
 * @property-read \App\Models\Product $product
 * @property-read \App\Models\OrderRefund|null $refund
 * @property-read \App\Models\ProductSku $sku
 * @method static \Database\Factories\OrderItemFactory factory(...$parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem query()
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereAmount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereCost($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereDeliveryData($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereDeliveryStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem wherePrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereProductSkuId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereProductTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereRefundFailedReason($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereRefundNumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereRefundStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereSkuAttrValue($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereSkuAttrValueIndex($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereSkuName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereTotalAmount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereTotalCost($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereVendorId($value)
 * @mixin \Eloquent
 * @property-read \App\Models\Vendor|null $vendor
 * @property string|null $product_cover
 * @property string|null $sku_pic
 * @property string $profit final price
 * @property string $total_profit
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereProductCover($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereProfit($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereSkuPic($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OrderItem whereTotalProfit($value)
 * @property-read \App\Models\OrderRefund|null $refunds
 */
class OrderItem extends Model
{
    use HasFactory;
	
	protected $guarded = ['id'];
	
	protected $casts = [
		'sku_attr_value' => 'json',
	];
	
	public function vendor()
	{
		return $this->belongsTo(Vendor::class);
	}
	
	public function product()
	{
		return $this->belongsTo(Product::class);
	}
	
	public function sku()
	{
		return $this->belongsTo(ProductSku::class, 'product_sku_id', 'id');
	}
	
	public function order()
	{
		return $this->belongsTo(Order::class, 'order_id', 'id');
	}
	
	public function refund()
	{
		return $this->hasOne(OrderRefund::class);
	}
}
